﻿
#ifndef CODE_GENERATOR_HXX
#define CODE_GENERATOR_HXX

#include "Node.h"
#include "rutil/Data.hxx"

namespace codegen
{
    class Generator
    {
    public:
        Generator(const resip::Data& class_name, const resip::Data& base_class_name = resip::Data::Empty);
        virtual ~Generator();

        bool is_well_formed() const;
        const resip::Data& errors() const { return errors_; }
        virtual EncodeStream& encode(EncodeStream& ostm) const;
        const resip::Data& get_class_name() const { return class_name_; }
        const resip::Data& get_base_class_name() const { return base_class_name_; }

    protected:
        void check_parsed() const;
        void do_parse() const;

        virtual bool parse() = 0;

        virtual EncodeStream& encode_all(EncodeStream& ostm) const;
        virtual EncodeStream& encode_header(EncodeStream& ostm) const;
        virtual EncodeStream& encode_class(EncodeStream& ostm) const = 0;
        virtual EncodeStream& encode_footer(EncodeStream& ostm) const;

        void add_error(const resip::Data& reason, const Node* node = 0);

        bool formed_;
        bool parsed_;
        resip::Data errors_;
        resip::Data class_name_;
        resip::Data base_class_name_;
    };
}

#endif // #ifndef CODE_GENERATOR_HXX
